package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.brandbo.BrandCreateBO;
import com.cskaoyan.bean.brandbo.BrandListBO;
import com.cskaoyan.bean.brandbo.BrandUpdateBO;
import com.cskaoyan.bean.brandvo.BrandListVO;
import com.cskaoyan.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * 创建日期: 2022/05/06 15:54
 *
 * @author shuyang
 */
@RestController
@RequestMapping("admin")
public class BrandController {
    @Autowired
    BrandService brandService;

    @RequestMapping("brand/list")
    public BaseRespVo<BrandListVO> queryBrandList(BrandListBO brandListBO) {
        BrandListVO brandListVO = brandService.selectBrands(brandListBO);
        return BaseRespVo.ok(brandListVO);
    }

    @PostMapping("brand/create")
    public BaseRespVo<MarketBrand> createBrand(@RequestBody BrandCreateBO brandCreateBO) {
        String desc = brandCreateBO.getDesc();
        String floorPrice = brandCreateBO.getFloorPrice();
        if (desc == null || "".equals(desc)) {
            return BaseRespVo.invalidData("参数不正确！");
        }
        try {
            BigDecimal bigDecimal = new BigDecimal(floorPrice);
        } catch (Exception e) {
            return BaseRespVo.invalidData("参数不正确！");
        }
        MarketBrand marketBrand = brandService.insertBrand(brandCreateBO);
        return BaseRespVo.ok(marketBrand);
    }

    @PostMapping("brand/update")
    public BaseRespVo<MarketBrand> updateBrand(@RequestBody BrandUpdateBO brandUpdateBO) {
        String desc = brandUpdateBO.getDesc();
        String floorPrice = brandUpdateBO.getFloorPrice();
        if (desc == null || "".equals(desc)) {
            return BaseRespVo.invalidData("参数不正确！");
        }
        try {
            BigDecimal bigDecimal = new BigDecimal(floorPrice);
        } catch (Exception e) {
            return BaseRespVo.invalidData("参数不正确！");
        }
        MarketBrand marketBrand1 = brandService.UpdateBrand(brandUpdateBO);
        return BaseRespVo.ok(marketBrand1);
    }
    @PostMapping("brand/delete")
    public BaseRespVo deleteBrand(@RequestBody MarketBrand marketBrand ){
        brandService.deleteBrand(marketBrand);
        return new BaseRespVo();
    }
}
